package com.hc.sss.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.LawMapper;
import com.hc.sss.pojo.Law;
import com.hc.sss.service.LawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LawServiceImpl implements LawService {

    @Autowired
    LawMapper lawMapper;

    /*删除法律*/
    public int deleteLaw(Integer lawId) {
        return lawMapper.deleteLaw(lawId);
    }

    /*添加法律*/
    public int insertLaw(Law law) {
        return lawMapper.insertLaw(law);
    }

    /*查询法律+分页*/
    public ResultMap<Law> findLawList(Map<String,Object> paramMap) {
        ResultMap<Law> resultMap = new ResultMap<Law>();
        Integer page = 1;
        Integer limit = 5;
        if (paramMap.get("page") != null && !"".equals(paramMap.get("page"))) {
            page = Integer.valueOf(paramMap.get("page").toString());
        }
        if (paramMap.get("limit") != null && !"".equals(paramMap.get("limit"))) {
            limit = Integer.valueOf(paramMap.get("limit").toString());
        }
        PageHelper.startPage(page, limit);
        List<Law> list = lawMapper.findLawList(paramMap);
        PageInfo<Law> info = new PageInfo<Law>(list);
        resultMap.setData(list);
        resultMap.setCount((int)info.getTotal());
        return resultMap;
    }

    /*修改法律*/
    public int updateLaw(Law law) {
        return lawMapper.updateLaw(law);
    }
}
